<template>
    <van-uploader v-model:model-value="files" :max-count="uploadConfig.max" accept="image/*" :disabled="uploading"
        :before-read="beforeRead" :after-read="afterRead" />
</template>

<script setup>
import { ref, defineProps, defineEmits } from 'vue'

const files = ref([])

const uploading = ref(false)


const props = defineProps({
    uploadConfig: Object
})

const emits = defineEmits()

const beforeRead = (file) => {
    // 验证文件大小和类型等
    if (file.size > 2 * 1024 * 1024) {
        Toast('图片大小不能超过2MB')
        return false
    }
    return true
}

const afterRead = (file) => {
    emits('file', file)

    // uploading.value = true;
    // 模拟上传
    setTimeout(() => {
        uploading.value = false
        // files.value.push({ url: file.content });
    }, 1000)
}

onMounted(() => {

})
</script>
